package com.ruoyi.web.controller.document;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.document.domain.ContractType;
import com.ruoyi.document.service.IContractTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同类型Controller
 * 
 * @author limengyao
 * @date 2023-03-04
 */
@RestController
@RequestMapping("/document/type")
public class ContractTypeController extends BaseController
{
    @Autowired
    private IContractTypeService contractTypeService;

    /**
     * 前端下拉列表展示的数据
     */

    @GetMapping("/selectContractData")
    public TableDataInfo selectContractData(ContractType contractType)
    {
        List<ContractType> list = contractTypeService.selectContractTypeList(contractType);
        return getDataTable(list);
    }
    /**
     * 查询合同类型列表
     */
    @PreAuthorize("@ss.hasPermi('document:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractType contractType)
    {
        startPage();
        List<ContractType> list = contractTypeService.selectContractTypeList(contractType);
        return getDataTable(list);
    }
    /**
     * 导出合同类型列表
     */
    @PreAuthorize("@ss.hasPermi('document:type:export')")
    @Log(title = "合同类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractType contractType)
    {
        List<ContractType> list = contractTypeService.selectContractTypeList(contractType);
        ExcelUtil<ContractType> util = new ExcelUtil<ContractType>(ContractType.class);
        util.exportExcel(response, list, "合同类型数据");
    }

    /**
     * 获取合同类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('document:type:query')")
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") Long contractId)
    {
        return success(contractTypeService.selectContractTypeByContractId(contractId));
    }

    /**
     * 新增合同类型
     */
    @PreAuthorize("@ss.hasPermi('document:type:add')")
    @Log(title = "合同类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractType contractType)
    {
        return toAjax(contractTypeService.insertContractType(contractType));
    }

    /**
     * 修改合同类型
     */
    @PreAuthorize("@ss.hasPermi('document:type:edit')")
    @Log(title = "合同类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractType contractType)
    {
        return toAjax(contractTypeService.updateContractType(contractType));
    }

    /**
     * 删除合同类型
     */
    @PreAuthorize("@ss.hasPermi('document:type:remove')")
    @Log(title = "合同类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable Long[] contractIds)
    {
        return toAjax(contractTypeService.deleteContractTypeByContractIds(contractIds));
    }
}
